package com.example.treehole.controller;

import com.example.treehole.bean.Course;
import com.example.treehole.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import com.example.treehole.common.BaseResult;
import org.springframework.http.ResponseEntity;

@RestController
@RequestMapping("/course")
public class CourseController {

    @Autowired
    private CourseService courseService;

    @PostMapping("/add")
    public ResponseEntity<?> addCourse(@RequestBody Course course) {
        boolean result = courseService.addCourse(course);
        if (result) {
            return BaseResult.ok("课程添加成功");
        } else {
            return BaseResult.error("该日期该节课已存在");
        }
    }

    @GetMapping("/get")
    public ResponseEntity<?> getCoursesByUserId(String userid) {
        List<Course> courses = courseService.getCoursesByUserId(userid);
        return BaseResult.ok("查询成功", courses);
    }

    @DeleteMapping("/delete")
    public ResponseEntity<?> deleteCourse( String id) {
        boolean result = courseService.deleteCourse(id);
        if (result) {
            return BaseResult.ok("课程删除成功");
        } else {
            return BaseResult.error("课程删除失败");
        }
    }
}